//
//  CDApplyView.swift
//  PDF
//
//  Created by Kellv on 2024/4/20.
//

import UIKit

class CDApplyView: UIView {
    var titelLabel:UILabel!
    var applySwi: UISwitch!
    var applyHandler: ((Bool)->Void)?
    override init(frame: CGRect) {
        super.init(frame: frame)
        titelLabel = UILabel()
        titelLabel.textColor = .black
        titelLabel.font = UIFont(name:  "HelveticaNeue-Regular", size: 14)
        titelLabel.text = "Apply to all pages".localize()
        self.addSubview(titelLabel)
        titelLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(16)
            make.centerY.equalToSuperview()
        }
        
        applySwi = UISwitch()
        self.addSubview(applySwi)
        applySwi.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-16)
            make.centerY.equalToSuperview()
        }
        applySwi.addTarget(self, action: #selector(onApplyValueChange), for: .valueChanged)

    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func onApplyValueChange(swi: UISwitch) {
        guard let applyHandler = applyHandler else {
            return
        }
        applyHandler(swi.isOn)
    }
}
